package com.molichuxing.services.infrastructure.service.impl;


import com.molichuxing.services.infrastructure.bean.ContractTemplateBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.ContractTemplateMapper;
import com.molichuxing.services.infrastructure.dto.response.ContractTemplateDto;
import com.molichuxing.services.infrastructure.service.ContractTemplateService;
import com.molichuxing.services.property.ContractBusinessTypeEnum;
import com.molichuxing.services.property.ContractTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 * 合同模板表 服务实现类
 * </p>
 *
 * @author zhaopenghui
 * @since 2019-09-11
 */
@Service("contractTemplateService")
public class ContractTemplateServiceImpl implements ContractTemplateService {

    @Autowired
    ContractTemplateMapper contractTemplateMapper;

    /**
     * 根据业务类型获取合同模板
     *
     * @param businessType
     * @return
     */
    @Override
    public List<ContractTemplateDto> getByGoodsType(Integer businessType) {
        return Convert.toContractTemplateDto(contractTemplateMapper.getByGoodsType(businessType));
    }

    /**
     * 根据ids获取合同模板
     *
     * @param ids
     * @return
     */
    @Override
    public List<ContractTemplateDto> getByIds(List<Integer> ids) {
        List<ContractTemplateBean> beanList = contractTemplateMapper.getByIds(ids);
        return Convert.toContractTemplateDto(beanList);
    }

    /**
     * 根据模板类型获取合同模板
     *
     * @param templateType
     * @return
     */
    @Override
    public List<ContractTemplateDto> getByTemplateType(Integer templateType) {
        return Convert.toContractTemplateDto(contractTemplateMapper.getByTemplateType(templateType));
    }

    /**
     * 查询有效合同模板
     *
     * @param businessType 业务类型
     * @param templateType 模板类型
     * @return
     */
    @Override
    public ContractTemplateDto getEffectiveTemplate(ContractBusinessTypeEnum businessType, ContractTypeEnum templateType) {
        List<ContractTemplateBean> beans = contractTemplateMapper.getEffectiveTemplate(businessType.getValue(),
                templateType.getValue(), false);

        return beans == null ? null : beans.isEmpty() ? null : Convert.toContractTemplateDto(beans.get(0));
    }


}
